<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>表信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <link rel="stylesheet" href="${ctx}/systemStatic/style/systemStyle.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>

<script type="text/html" template>

    <div style="height: 100%;text-align: center;padding: 0px 20px;box-sizing: border-box;">
        <form id="baseInfoForm" method="post" class="layui-form" action="${ctx}/extend/codeGen/genCodes" style="text-align:center;" lay-filter="dataForm">
            <input type="txt" name="tableName" class="tableName" style="display: none">
            <input type="txt" name="colsList" class="colsList" style="display: none">

            <div class="layui-row">
                <div class="layui-col-xs6">
                    <label class="ccpui-generator-form-label" style="margin-top: 15px;">基本路径</label>
                    <div class="ccpui-generator-input-block">
                        <input type="text" id="basePackage" name="basePackage" lay-verify="required" placeholder="参照格式:com.ccp.dev"
                               autocomplete="off" class="layui-input" maxlength="50" value="com.ccp.dev"/>
                    </div>
                    <label class="ccpui-generator-form-label">模块名</label>
                    <div class="layui-input-block">
                        <input type="text" id="moduleName" name="moduleName" lay-verify="required" placeholder="参考模块名：user"
                               autocomplete="off" class="layui-input" maxlength="50" />
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <label class="ccpui-generator-form-label" style="margin-top: 15px;">自定义类名</label>
                    <div class="ccpui-generator-input-block">
                        <input type="text" name="classForClassName" id="classForClassName"  placeholder="非必填项，不填写默认按照驼峰规范命名"
                               autocomplete="off" class="layui-input" maxlength="50" />
                    </div>
                    <label class="ccpui-generator-form-label">作者</label>
                    <div class="ccpui-generator-input-block">
                        <input type="text" id="author" name="author" lay-verify="required" placeholder="请输入作者"
                               autocomplete="off" class="layui-input" maxlength="50" />
                    </div>
                </div>
                <div class="layui-col-xs6" style="display: none">
                    <label class="ccpui-generator-form-label">主键</label>
                    <div class="layui-input-block" style="width: 79%;">
                        <div class="ccpui-generator-input-block" id="primarySelect" style="text-align: left;margin-left: 0px;">
                        </div>
                    </div>
                    <label class="ccpui-generator-form-label">显示完整页面</label>
                    <div class="ccpui-generator-input-block" style="float: left;margin: 0px 0px 7px 6px;padding-left: 10px;">
                        <input name="isShowFull" type="radio" value="true" title="是"/>
                        <input name="isShowFull" type="radio" value="false" checked='checked' title="否"/>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <label class="ccpui-generator-form-label">流程选择</label>
                    <div class="layui-input-block" style="margin-bottom: 7px;">
                        <input type="text" id="flow" name="flow" placeholder="请输入要绑定的流程Key" autocomplete="off" class="layui-input" maxlength="50" />
                    </div>
                    </div>
                <div class="layui-col-xs6" style="float: right">
                    <label class="ccpui-generator-form-label">打开方式</label>
                    <div class="ccpui-generator-input-block" style="float: left;margin: 0px 0px 7px 6px;padding-left: 10px;">
                        <input name="selectOpenMode" lay-filter="selectOpenMode" type="radio" value="true" checked title="弹出窗口"/>
                        <input name="selectOpenMode" lay-filter="selectOpenMode" type="radio" value="false" title="跳转页面"/>
                    </div>
                </div>
            </div>
            <div class="showColumnInCodeGenerator">
                <table id="showInfoTable" lay-filter="showTableInfo"></table>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs12">
                    <div class="layui-form-item" style="position: fixed;bottom: 15px;left: 0;margin-bottom: 0;width: 100%;">
                        <div class="layui-input-block" style="margin: 15px 110px 0px 110px;">
                            <button type="submit" class="layui-btn btn-n" id="subBtn" lay-filter="subBtn" lay-submit>立即生成</button>
                            <button type="button" id="closeWindow" class="layui-btn btn-n layui-btn-danger btn-save">关闭</button>
                        </div>
                    </div>
                </div>
            </div>

        </form>
    </div>

</script>

<script type="text/html" id="titleTpl">
    <select class="layui-yonyou-select" lay-ignore name="attrType" lay-filter="attrType" id="{{d.columnName}}_attrType">
        <option value="">请选择</option>
        <option value="Boolean" {{# if(d.attrType=="Boolean"){}} selected {{#}}}>Boolean</option>
        <option value="BigDecimal" {{# if(d.attrType=="BigDecimal"){}} selected {{#}}}>BigDecimal</option>
        <option value="Date" {{# if(d.attrType=="Date"){}} selected {{#}}}>Date</option>
        <option value="Double" {{# if(d.attrType=="Double"){}} selected {{#}}}>Double</option>
        <option value="Float" {{# if(d.attrType=="Float"){}} selected {{#}}}>Float</option>
        <option value="Integer" {{# if(d.attrType=="Integer"){}} selected {{#}}}>Integer</option>
        <option value="Long" {{# if(d.attrType=="Long"){}} selected {{#}}}>Long</option>
        <option value="String" {{# if(d.attrType=="String"){}} selected {{#}}}>String</option>
        <option value="byte[]" {{# if(d.attrType=="byte[]"){}} selected {{#}}}>byte[]</option>
    </select>
</script>
<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    var colsInfo;
    //一般直接写在一个js文件中
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'setter', 'form','jquery'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var table = layui.table;
        var setter = layui.setter;

        //关闭当前页面
        $("#closeWindow").click(function () {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        })

        //表名称
        var tableName = '${tableName}';
        $(".tableName").val(tableName);
        var classForClassName = '${classForClassName}';
        $("#classForClassName").val(classForClassName);

        //查询所有列信息并放入下拉中
        var url = '${ctx}/extend/codeGen/queryColumnKey?tableName=' + tableName;
        $.ajax({
            url: url,
            type: "GET",
            contentType: 'application/json',
            dataType: 'json',
            success : function(datas) {
                var data = datas.data;
                //加载数据
                var html = '<select id="primaryKeyColumn" name="primaryKeyColumn" lay-verify="required" lay-filter="primaryKeyColumn">';
                for (var i = 0; i < data.length; i++) {
                    if("PRIMARY" === data[i].columnkey){
                        html += '<option selected value="' + data[i].columnName+ '">' + data[i].columnName + '</option>';
                    }else{
                        html += '<option value="' + data[i].columnName+ '">' + data[i].columnName + '</option>';
                    }
                }
                html += '</select>';
                $("#primarySelect").append(html);
                form.render('select');
            }
        });

        //第一个实例
        table.render({
            elem: '#showInfoTable'
            , url:'${ctx}/extend/codeGen/showinfo?tableName=' + tableName
            , title: '数据库表字段信息'
            , method: 'post'
            , height: '330'
            , cols: [[ //表头
                {field: 'columnName', title: '字段名', sort: true}
                , {field: 'dataType', title: '数据类型', sort: true}
                , {field: 'dataLength', title: '数据长度', sort: true}
                , {field: 'columnComment', title: '字段描述'}
                , {
                    field: 'attrNameForProperty', title: 'Java属性名称'
                    , templet: function (data) {
                        return "<input type='text' class='layui-input' lay-ignore name='"+data.columnName+"_attrNameForProperty' id='"+data.columnName+"_attrNameForProperty' value='" + data.attrNameForProperty + "'>";
                    }
                }
                , {field: 'attrType', title: 'Java属性类型', templet: '#titleTpl'}
                , {
                    field: 'columnComment', title: 'Java属性注释'
                    , templet: function (data) {
                        return "<input type='text' class='layui-input' lay-ignore id='"+data.columnName+"_comment'   value='" + data.columnComment + "'>";
                    }
                }
                ,{
                    field: 'asQuery', title: '查询条件'
                    , templet: function (data) {
                        return "<input name='"+data.columnName+"_asQuery' type='radio' value='true' checked='checked'/>是"
                            +"<input name='"+data.columnName+"_asQuery' type='radio' value='false' />否"
                            ;
                    }
                },{
                    field: 'asShowCol', title: '列表展示'
                    , templet: function (data) {
                        return "<input name='"+data.columnName+"_asShowCol' type='radio' value='true' checked='checked'/>是"
                            +"<input name='"+data.columnName+"_asShowCol' type='radio' value='false' />否"
                            ;
                    }
                },{
                    field: 'asFormCol', title: '表单输入'
                    , templet: function (data) {
                        return "<input name='"+data.columnName+"_asFormCol' type='radio' value='true' checked='checked' />是"
                            +"<input name='"+data.columnName+"_asFormCol' type='radio' value='false'  />否"
                            ;
                    }
                }
            ]]
            , done: function (date) {
                colsInfo=date;
            }
        });
        /**
         * 表单提交
         */
        $("form").submit(function () {
            var colsArray = colsInfo.data;
            for (var i = 0; i < colsArray.length; i++) {
                var attrNameForProperty = $("input[name='"+colsArray[i].columnName+"_attrNameForProperty']").val();
                colsArray[i].attrNameForProperty = attrNameForProperty;

                var columnComment = $("input[id='"+colsArray[i].columnName+"_comment']").val();
                colsArray[i].columnComment = columnComment;

                var attrType= $("#"+colsArray[i].columnName+"_attrType").val();
                colsArray[i].attrType = attrType;

                var asQuery= $("input[name='"+colsArray[i].columnName+"_asQuery']:checked").val();
                colsArray[i].asQuery = asQuery;

                var asFormCol= $("input[name='"+colsArray[i].columnName+"_asFormCol']:checked").val();
                colsArray[i].asFormCol = asFormCol;

                var asShowCol= $("input[name='"+colsArray[i].columnName+"_asShowCol']:checked").val();
                colsArray[i].asShowCol = asShowCol;

                console.log(colsArray[i]);
            }
            $(".colsList").val(JSON.stringify(colsArray));
            var index = parent.layer.getFrameIndex(window.name);
//            window.parent.layer.close(index);
            window.parent.layer.msg('执行成功,正在生成代码请稍后…', {icon: 1});
        })
    });
</script>
<style>
    .showColumnInCodeGenerator .layui-input{
        height: 26px;
    }
</style>
</body>
</html>